<?php
    function getGps($gps){
        return $gps ? $gps : '未安装';
    }
?>
<style>
	.step{position:relative;}
</style>
<form class="page-list-form" action="__APP__/Loan/index.html" method="get">
	<div class="layui-btn-group">
		<a href="__APP__/Loan/add.html" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe654;</i>添加</a>
		<a data-href="__APP__/Loan/del.html" class="layui-btn layui-btn-primary j-page-btns confirm"><i class="layui-icon">&#x1006;</i>删除</a>
		<a data-href="__APP__/Loan/toemail.html" class="layui-btn layui-btn-primary j-page-btns confirm"><i class="layui-icon">&#xe609;</i>查询征信</a>
	</div>
	<div class="layui-form page-filter fr">
		<div class="layui-input-inline">{html:select name="salesman" options=":Cache('Salesman')" first="--业务经理--" }</div>
		<div class="layui-input-inline">{html:select name="step" options=":LinkageList('BorrowStep')" first="--进度--"}</div>
		<div class="layui-inline">
			<label class="layui-form-label">搜索</label>
			<div class="layui-input-inline"><input type="text" name="keywords" lay-verify="required" placeholder="请输入关键词搜索" autocomplete="off" class="layui-input" value="{:input('keywords')}"></div>
		</div>
	</div>
	<div class="layui-form">
		{Data:list name="Loan" keywords="request" order="step asc,id desc"}
		<table class="layui-table mt10" lay-even="" lay-skin="row">
			<colgroup>
				<col width="50">
				<col width="110">
				<col width="80">
				<col width="80">
				<col width="90">
				<col width="80">
				<col width="80">
				<col width="90">
				<col width="80">
				<col >
				<col width="260">
			</colgroup>
			<thead>
				<tr>
					<th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
					<th>录入时间</th>
					<th>业务员</th>
					<th>申请人</th>
					<th>进度</th>
					<th>金额</th>
					<th>核准</th>
					<th>手机</th>
					<th>GPS</th>
					<th>备注</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				{volist name="var.list" id="vo"}
				<tr id="res{$vo.id}" class="step-{$vo.step}">
					<td><input type="checkbox" name="ids[]" value="{$vo.id}" class="layui-checkbox checkbox-ids" lay-skin="primary"></td>
					<td>{$vo.date}</td>
					<td>{$vo.salesman.realname}</td>
					<td>{$vo.realname}</td>
					<td><span class="step" data-val="{$vo.step}" data-id="{$vo.id}">{$vo.step|Linkage='BorrowStep'}</span></td>
					<td>{$vo.money}</td>
					<td>{$vo.final_money}</td>
					<td>{$vo.phone}</td>
					<td>{$vo.gps|getGps}</td>
					<td>{$vo.remark}</td>
					<td>
						<div class="layui-btn-group">
						<a href="__APP__/Loan/edit/id/{$vo.id}.html" class="layui-btn layui-btn-primary layui-btn-sm"><i class="fa fa-edit"></i></a>
						<a href="__APP__/Loan/tools/id/{$vo.id}.html" class="layui-btn layui-btn-primary layui-btn-sm" target="_blank"><i class="layui-icon">&#xe857;</i></a>
						<a href="__APP__/Loan/attach/ids/{$vo.id}.html" class="layui-btn layui-btn-primary layui-btn-sm" title="附件"><i class="fa fa-file-archive-o"></i></a></div>
					</td>
				</tr>
				{/volist}
			</tbody>
		</table>
		{$var.page|raw}
		{/Data:list}
	</div>
</form>
<div class="layui-form-select spaceClose" id="StepTpl" style="width:100px;position:absolute;">
	<dl class="layui-anim layui-anim-upbit">
		{volist name=":LinkageList('BorrowStep')" id="stvo"}
		<dd lay-value="{$key}">{$stvo}</dd>
		{/volist}
	</dl>
</div>
<script type="text/javascript">
    layui.use('jquery',function(){
        var $ = layui.jquery;
        $('.step').on('click',function(){
            $('#StepTpl dd').removeClass('layui-this');
            $('#StepTpl dd[lay-value='+$(this).attr('data-val')+']').addClass('layui-this');
            $('#StepTpl').css({
                top:$(this).offset().top-10,
                left:$(this).offset().left
            }).attr('data-id',$(this).attr('data-id')).addClass('layui-form-selected');
        })
        $('#StepTpl dd').on('click',function(){
            var id= $('#StepTpl').attr('data-id');
            var val = $(this).attr('lay-value');
            var txt = $(this).text();
            Ajax.post('__APP__/Loan/attr.html',{field:'step',ids:id,val:val},function(d){
                $('#res'+id+' .step').attr('data-val',val).html(txt);
                layer.msg(d.msg,{icon:1});
            })
            $('#StepTpl').removeClass('layui-form-selected');
        });
        /*$('.step').each(function(k, el) {
            $(this).html(html);
            $(this).find('select').val($(this).attr('data-val')).on('change',function(){
                var id = $(this).parents('tr').attr('id').replace('res','');
                var v = $(this).val();
                Ajax.post('__URL__/update.html',{id:id,step:v})
                //console.info($(this).val());
            });
        });*/
        $('#Step,#Salesman').on('change',function(){
            var n = $(this).attr('name');
            var v = $(this).val();
            window.location.href= '__APP__/Loan/index.html?'+n+'='+v;
        });
        $(document).on('click',function(e){
            if(!$(e.target).hasClass('step') && $(e.target).parents('.layui-form-select').length==0){
                $('.spaceClose').removeClass('layui-form-selected')
            }
        });

        
    })
</script>

